﻿// EasyTcpClient.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。

//#define _WINSOCK_DEPRECATED_NO_WARNINGS   设置sdl检查为否

#include "EasyTcpClient.hpp"
#include <thread>

bool g_Run = true;
void cmdThread(EasyTcpClient * client)
{
    while (g_Run)
    {
        char szCmdBuff[256] = {};
        printf("请输入指令:\t");
        scanf("%s", szCmdBuff);
        if (0 == strcmp(szCmdBuff, "exit"))
        {
            client->Close();
            printf("退出Thread进程。\n");
            return;
        }
        else if (0 == strcmp(szCmdBuff, "login"))
        {
            Login login;
            strcpy(login.userName, "stract");
            strcpy(login.passWord, "qyuse");
            client->SendDate(&login);
        }
        else if (0 == strcmp(szCmdBuff, "logout"))
        {
            Logout logout;
            strcpy(logout.userName, "stract");
            client->SendDate(&logout);
        }
        else
        {
            printf("不支持的命令。");
        }
    }
}

int main(int argc, char** argv)
{
    EasyTcpClient client;
    //1.建立Socket
    client.InitSocket();


    //2.连接服务器
    client.Connect("127.0.0.1",4567);
   
    //3.接收服务器传送过来的消息
  //  DataPackage datapackage;

    std::thread t1(cmdThread, &client);
   
    t1.detach();
   

    //4.处理请求命令
    while (client.IsRun())
    {
        client.OnRun();
      
    }


    //5.关闭socket
    client.Close();
   
    printf("已退出。\n");
    getchar();
    return 0;
}


